﻿<%
class BlogCommentClass
    public blogId, itemId, title
    public commentId,parentId, detail, insertTime
    public userId, userName, email, webUrl, face
    public isSecret

    public function load(comment_id)
        dim sql, rs
        set rs = Server.CreateObject("ADODB.Recordset")
        call openDB
        load = false
        if isEmpty(comment_id) Or IsNull(comment_id) then
            exit function
        end if
        commentId = clng(comment_id)
        
        sql = " select a.title,a.is_secret as content_secret,b.blog_id, b.content_id,b.parent_id, b.comment_id, b.detail, b.insert_time,b.update_time, b.user_id, b.user_name, b.is_secret, b.email, b.web_url, b.face from blog_content a, blog_comments b  where a.content_id=b.content_id and  b.comment_id=" & commentId 
        
        rs.open sql,conn,1,1

        dim count, blogComment
        count = rs.recordCount
        redim m_comments(count)
        if count>0 then
           buildFromRS(rs)
           load = true
        end if    
        rs.close()
        set rs = nothing
    end function
    
    public function build(array)
        build = false
        if isEmpty(array) or not isArray(array) then
            exit function
        end if
        if ubound(array)<13 then
            exit function
        end if    

        blogId      = array(0) 
        itemId      = array(1) 
        title       = array(2) 
        commentId   = array(3) 
        parentId    = array(4) 
        detail      = array(5) 
        insertTime  = array(6) 
        userId      = array(7) 
        userName    = array(8) 
        email       = array(9) 
        webUrl      = array(10) 
        face        = array(11) 
        isSecret    = array(12) 
        
        build = true
    end function
    
    public function toArray()
        dim array(13)
        array(0) = blogId
        array(1) = itemId
        array(2) = title
        array(3) = commentId
        array(4) = parentId
        array(5) = detail
        array(6) = insertTime
        array(7) = userId
        array(8) = userName
        array(9) = email
        array(10) = webUrl
        array(11) = face
        array(12) = isSecret
        
        toArray = array
    end function
    
    public function buildFromRS(rs)
        buildFromRS = false
        if isEmpty(rs) or not isObject(rs) then
            exit function
        end if
        if rs.bof or rs.eof then
            exit function
        end if
        
        commentId   = rs("comment_id")

        on error resume next

        blogId      = rs("blog_id")
        itemId      = rs("content_id") 
        parentId    = rs("parent_id") 
        insertTime  = rs("insert_time") 
        userId      = rs("user_id")
        userName    = rs("user_name")
        email       = rs("email")
        webUrl      = rs("web_url")
        face        = rs("face")
        isSecret    = rs("is_secret") 
        title       = rs("title") 
        detail      = rs("detail")
        
        if rs("content_secret")=True then
            isSecret = True
        end if        

        on error goto 0
                
        buildFromRS = true
    end Function
    
    Private blogItem, parentComment
    
    Public Function getBlogItem()
        If IsEmpty(blogItem)  Then 
            Set blogItem = New BlogItemClass
            blogItem.load(blogId)
        End If 
        Set getBlogItem = blogItem
    End Function
    
    Public Function getParentComment()
        If IsEmpty(parentComment) Then
            Set parentComment = New BlogCommentClass
            parentComment.load(parentId)
        End If
        Set getParentComment = parentComment
    End Function
    
    
end class
%>

